package com.suse.controller;

import com.suse.dto.UserInfoDto;
import com.suse.pojo.UserInfo;
import com.suse.service.UserInfoService;
import com.suse.util.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/user")
public class UserInfoController {
    @Autowired
    UserInfoService service;

    @GetMapping("/add")
    public ResultVo add(UserInfo u) {
        return service.add(u);
    }

    @PostMapping("/update")
    public ResultVo update(@RequestBody UserInfo u) {
        return service.update(u);
    }

    @GetMapping("/del")
    public ResultVo del(int id) {
        return service.del(id);
    }

    @GetMapping("/query")
    public ResultVo query(UserInfoDto dto) {
        return service.select(dto);
    }

    //登录
    @PostMapping("/login")
    public ResultVo login(@RequestBody UserInfo u, HttpServletRequest request) {
        return service.login(u, request);
    }

    //发送验证码
    @GetMapping("/sendCode")
    public ResultVo sendCode(String email, HttpServletRequest request) {
        return service.sendCode(email, request);
    }

    //验证码登录
    @GetMapping("/loginCode")
    public ResultVo loginCode(String code, HttpServletRequest request) {
        return service.loginCode(code, request);
    }

    // 文件上传
    @PostMapping("/upload")
    public ResultVo upload(@RequestParam("file") MultipartFile file,HttpServletRequest request) {
        return service.fileUpload(file, request);
    }
}
